import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QFileDialog

from out_ui_py.demo_main_window import Ui_MainWindow
from out_ui_py.child_form import Ui_Form

from qt_material import list_themes
from qt_material import apply_stylesheet
from pprint import pprint


class ChildrenFrom(QWidget, Ui_Form):
    def __init__(self):
        super(ChildrenFrom, self).__init__()
        self.setupUi(self)


class MyMainForm(QMainWindow, Ui_MainWindow):

    def __init__(self):
        super(MyMainForm, self).__init__()
        self.setupUi(self)

        pprint('总计主题样式：{} 种！'.format(len(list_themes())))
        pprint(list_themes())

        # 生成子窗口实例
        self.child = ChildrenFrom()

        # 菜单的点击事件
        self.fileCloseAction.triggered.connect(self.close)
        self.fileOpenAction.triggered.connect(self.openMsgSlot)

        self.addWinAction.triggered.connect(self.childShowSlot)

    def openMsgSlot(self):
        file, ok = QFileDialog.getOpenFileName(
            self, "打开", "C:/", "All Files(*);;Text Files(*.txt)")
        # 状态栏显示文件地址
        self.statusBar.showMessage(file)

    def childShowSlot(self):
        # 添加子窗口
        self.mainGridLayout.addWidget(self.child)
        self.child.show()


if __name__ == "__main__":
    app = QApplication(sys.argv)
    apply_stylesheet(app, theme="light_orange.xml")
    win = MyMainForm()

    win.show()
    sys.exit(app.exec())
